#include "guardian.h"
#include "ui_guardian.h"
#include "SpellEffect.h"
#include "Ability.h"
#include "Rotation.h"
#include "RatingConvert.h"
#include <fstream>

Guardian::Guardian(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::Guardian)
{
    ui->setupUi(this);
    updateStatBoxes();
}

Guardian::~Guardian()
{
    delete ui;
}

enum STATS {
    AIM = 0, CUNNING, STRENGTH, WILLPOWER = 3,
    CRIT, SURGE, ALACRITY , POWER , ACCURACY = 8,
    DEFENSE, SHIELD, ABSORB, ARMOR = 12,
    LEVEL, MH_ACC, OH_ACC, ENEMY_LEVEL, ENEMY_ARMOR= 17,
    SPEED,  MH_MAX, MH_MIN, OH_MAX , OH_MIN =22,
    TECH_CRIT_CHANCE , TECH_CRIT_SIZE, TECH_BONUS_HEALING, TECH_BONUS_DAMAGE = 26,
    RANGED_CRIT_CHANCE , RANGED_CRIT_SIZE, RANGED_BONUS_DAMAGE = 29,
    FORCE_CRIT_CHANCE , FORCE_CRIT_SIZE, FORCE_BONUS_HEALING, FORCE_BONUS_DAMAGE = 33,
    MELEE_CRIT_CHANCE , MELEE_CRIT_SIZE, MELEE_BONUS_DAMAGE = 36,
    TECH_POWER, FORCE_POWER = 38
};

//define global Mercenary variables
QString guardRotationOutput;
QString &guardRotationRef = guardRotationOutput;


//create a holder for the stats
std::vector <double> guardStats(39,0);


void Guardian::setStats()
{
    int accBuff = 0;
    int critBuff = 3*(ui->skillBox_3->value());
    critBuff += 2*(ui->skillBox_2->value());
    if(ui->smugglerCheckBox->isChecked()) critBuff += 5;
    int ForceSurgeBuff = 3*(ui->skillBox_4->value());
    //int aimUpgBuff = 3*(ui->skillBox_1->value());
    int alacBuff = 2*(ui->skillBox_6->value());
    if(ui->skillBox_5->value()==2) alacBuff += 5;

    int aim = ui->primaryBox->value();
    if(ui->consularCheckBox->isChecked()) aim *= 1.05;

    guardStats.at(STRENGTH) = aim;
    guardStats.at(WILLPOWER) = ui->secondaryBox->value();
    guardStats.at(CRIT)= ui->critBox->value();
    guardStats.at(SURGE)= ui->surgeBox->value();
    guardStats.at(POWER)= ui->powerBox->value();
    guardStats.at(FORCE_POWER) = ui->techBox->value();
    guardStats.at(ALACRITY)= ui->alacBox->value();
    guardStats.at(LEVEL)= ui->levelBox->value();

    guardStats.at(ACCURACY) = ui->accBox->value();
    guardStats.at(MH_MAX) = ui->MHmaxBox->value();
    guardStats.at(MH_MIN) = ui->MHminBox->value();
    guardStats.at(ENEMY_LEVEL) = ui->enemyLevelBox->value();
    guardStats.at(ENEMY_ARMOR) = ui->enemyArmorBox->value();

    guardStats.at(FORCE_CRIT_CHANCE) = ( ForceCritChance(guardStats, critBuff, true));
    guardStats.at(FORCE_CRIT_SIZE) = ( ForceCritSize(guardStats, ForceSurgeBuff));
    guardStats.at(SPEED) =( Speed(guardStats, alacBuff));
    guardStats.at(MH_ACC) = (MH_Accuracy(guardStats, accBuff));
    guardStats.at(FORCE_BONUS_DAMAGE) = ForceBonusDamage(guardStats, true);
    guardStats.at(MELEE_CRIT_CHANCE) = ( MeleeCritChance(guardStats, critBuff, false));
    guardStats.at(MELEE_CRIT_SIZE) = ( MeleeCritSize(guardStats, 0));
    guardStats.at(MELEE_BONUS_DAMAGE) = MeleeBonusDamage(guardStats, false);

    guardStats.at(ARMOR) = ui->armorBox->value();
    guardStats.at(DEFENSE) = ui->defBox->value();
    guardStats.at(SHIELD) = ui->shieldBox->value();
    guardStats.at(ABSORB) = ui->absorbBox->value();

}

vector <double> Guardian::calculateStats(vector <double> &stats2){
    int accBuff = 0;
    int critBuff = 3*(ui->skillBox_3->value());
    critBuff += 2*(ui->skillBox_2->value());
    if(ui->smugglerCheckBox->isChecked()) critBuff += 5;
    int techSurgeBuff = 3*(ui->skillBox_4->value());
    int rangedSurgeBuff = 0;
    //int aimUpgBuff = 3*(ui->skillBox_1->value());
    int alacBuff = 2*(ui->skillBox_6->value());
    if(ui->skillBox_5->value()==2) alacBuff += 5;

    stats2.at(FORCE_CRIT_CHANCE) = ( ForceCritChance(stats2, critBuff, true));
    stats2.at(FORCE_CRIT_SIZE) = ( ForceCritSize(stats2, techSurgeBuff));
    stats2.at(SPEED) =( Speed(stats2, alacBuff));
    stats2.at(MH_ACC) = (MH_Accuracy(stats2, accBuff));
    stats2.at(FORCE_BONUS_DAMAGE) = ForceBonusDamage(stats2, true);
    stats2.at(MELEE_CRIT_CHANCE) = ( MeleeCritChance(stats2, critBuff, false));
    stats2.at(MELEE_CRIT_SIZE) = ( MeleeCritSize(stats2, rangedSurgeBuff));
    stats2.at(MELEE_BONUS_DAMAGE) = MeleeBonusDamage(stats2, false);
    //Armor SW: (BAV Heavy 3601)*(Stance 1.6) or 3601*1.6 = 5761.6
    //Armor DR: SW: (BADR 34.78%) + (Stance 6%) = 40.78%
    //DR Buff: SW: (Sonic Barrier Value Unknown)
    //Shield: SW: (Shield Base 5%) + (Stance 15%) + (Shield Specialization 4%)  = 24%
    //Absorb: SW: (Premium Shield Base 20%) = 20%
    //Defense: SW: (Base 5%) + (Guard Stance 6%) + (Blade Barricade 6%) = 17% or 22% w/Smash

    return stats2;
}

double Guardian::getMitigation(int d_armor, int d_def, int d_shield, int d_absorb){

    //    double base_DR = 1*(ui->skillBox_7->value()) + 5*(ui->skillBox_1->value());
    //    double base_armor_mult = 1 + 0.2*(ui->skillBox_6->value());
    //    if(ui->combatTechButton->isChecked()){ base_armor_mult+= 1.558;}
    //        double base_def_per = 15 + 2*(ui->skillBox_3->value()) + 1*(ui->skillBox_4->value());
    //        double base_shld_per = 5 + 15*(ui->skillBox_2->value());
    //        if(ui->combatTechButton->isChecked()){ base_shld_per+= 15;}
    //        double base_abs_per = 20 + 2*(ui->skillBox_5->value());

    //        if((ui->check2pcBox->isChecked())&&(ui->skillBox_2->value()>0)){
    //            base_shld_per += 5;
    //        }
    //        if(ui->check4pcBox->isChecked()){
    //            base_DR += 2;
    //        }
    double base_DR;
    double base_armor_mult;
    double base_def_per;
    double base_shld_per;
    double base_abs_per;
    base_DR = 6;
    base_armor_mult = 1.615;
    base_def_per = 17;
    base_shld_per = 24;
    base_abs_per = 20;

    double attLevel = ui->enemyLevelBox->value();
    double level = ui->levelBox->value();
    double attAcc = 1+0.05*(attLevel-level), attCrit = 0.1, attSurge = 0.5;
    double genShield = 0, genAbsorb = 0;

    double armor = ui->armorBox->value() + d_armor*base_armor_mult;
    double defense_rating = ui->defBox->value() + d_def;
    double shield_rating = ui->shieldBox->value() + d_shield;
    double absorb_rating = ui->absorbBox->value()+d_absorb;

    double armorDR= Armor(level, base_DR, armor);
    double defense = Defense(level, base_def_per, defense_rating);
    double shield = Shield(level, base_shld_per, shield_rating, genShield);
    double absorb = Absorb(level, base_abs_per, absorb_rating, genAbsorb);
    double mitigation = 100*(1 - ((min(attAcc - defense, 1.0)) * (1 - armorDR / 100)*(attCrit * (1 + attSurge) + min(shield, 1 - attCrit)*(1 - absorb) + max(1 - shield - attCrit, 0.0))));

    ui->defChanceBox->setText(QString::number(100*defense));
    ui->armor_DR_box->setText(QString::number(100*armorDR));
    ui->absorbPercentBox->setText(QString::number(100*absorb));
    ui->shieldChanceBox->setText(QString::number(100*shield));
    ui->DPSlabel->setText(QString::number(mitigation));

    return mitigation;
}

void Guardian::computeAlacrity(){
    ui->castView->clear();
    ui->countView->clear();
    setStats();
    vector <double> stats2=guardStats;
    QString alacOutput = "Haste%, RSh SCG casts, RSh Casts, SCG usages, HSc+RSc casts, HSc+RSc SCG casts, Total Casts, HPS\n\n";
    double rotationTime = ui->numCasts->value();
    int numCasts = ui->numCasts->value();
    double HPS;
    for(double m=0.0;m<39.5;m+=0.5){
        stats2.at(SPEED)=1-(m/100);
        if(ui->fixedTimeButton->isChecked()){
            //HPS = bodyguardRotation(rotationTime,stats2);
        }else{
            //HPS = bodyguardRotation(numCasts,stats2);
        }
        //        alacOutput += QString::number(m) +" , " + QString::number(RSh_SCG_count) +" ,  " + QString::number(RSh_count)
        //                +" , " + QString::number(SCG_count)+" , " + QString::number(RSc_count+HSc_count)
        //                + " , " + QString::number(RSc_SCG_count + HSc_SCG_count)+ " , " + QString::number(RSc_count + HSc_count+ES_count + RSh_count)
        //                +" , " + QString::number(HPS) +"\n";
    }
    ui->countView->insertPlainText(alacOutput);
}

void Guardian::updateStatBoxes()
{

    setStats();
    ui->forceCritChanceLabel->setText(QString::number(guardStats.at(FORCE_CRIT_CHANCE)));
    ui->forceCritSizeLabel->setText(QString::number(guardStats.at(FORCE_CRIT_SIZE)));
    ui->meleeCritChanceLabel->setText(QString::number(guardStats.at(MELEE_CRIT_CHANCE)));
    ui->meleeCritSizeLabel->setText(QString::number(guardStats.at(MELEE_CRIT_SIZE)));
    ui->speedLabel->setText(QString::number(100*(1-guardStats.at(SPEED))));
    ui->MHaccLabel->setText(QString::number(guardStats.at(MH_ACC)));
    ui->forceBonusDamageLabel->setText(QString::number(guardStats.at(FORCE_BONUS_DAMAGE)));
    ui->meleeBonusDamageLabel->setText(QString::number(guardStats.at(MELEE_BONUS_DAMAGE)));

    ui->primaryBox->setEnabled(true);
    ui->secondaryBox->setEnabled(true);
    ui->powerBox->setEnabled(true);
    ui->techBox->setEnabled(true);
    ui->critBox->setEnabled(true);
    ui->surgeBox->setEnabled(true);
    ui->alacBox->setEnabled(true);
    ui->accBox->setEnabled(true);
    ui->accBox_2->setEnabled(true);
    ui->accBox_3->setEnabled(true);
    ui->accuracyButton->setEnabled(true);
    ui->accLabel->setEnabled(true);
    ui->accLabel_2->setEnabled(true);
    ui->accLabel_3->setEnabled(true);
    ui->accWeightLabel->setEnabled(true);
    ui->MHaccLabel->setEnabled(true);
    ui->MHmaxBox->setEnabled(true);
    ui->MHmaxLabel->setEnabled(true);
    ui->MHminBox->setEnabled(true);
    ui->MHminLabel->setEnabled(true);
    ui->enemyArmorBox->setEnabled(true);
    ui->enemyArmorLabel->setEnabled(true);
    ui->enemyLevelBox->setEnabled(true);
    ui->enemyLevelLabel->setEnabled(true);
    ui->armorBox->setEnabled(false);
    ui->armorLabel->setEnabled(false);
    ui->defBox->setEnabled(false);
    ui->defLabel->setEnabled(false);
    ui->shieldBox->setEnabled(false);
    ui->shieldLabel->setEnabled(false);
    ui->absorbBox->setEnabled(false);
    ui->absorbLabel->setEnabled(false);
    ui->calcDPSButton->setText("Calculate DPS");
    ui->DPSlabel_1->setText("DPS");

    ui->powerButton->setText("Power");
    ui->aimButton->setText("Strength");
    ui->critButton->setText("Crit");
    ui->surgeButton->setText("Surge");
    ui->accuracyButton->setVisible(true);
    ui->alacrityButton->setVisible(true);

    ui->upg1Label->setText("Item 1 DPS: ");
    ui->upg2Label->setText("Item 2 DPS: ");

    if(ui->tree1->isChecked()){
        ui->primaryBox->setEnabled(false);
        ui->secondaryBox->setEnabled(false);
        ui->powerBox->setEnabled(false);
        ui->techBox->setEnabled(false);
        ui->critBox->setEnabled(false);
        ui->surgeBox->setEnabled(false);
        ui->alacBox->setEnabled(false);
        ui->accBox->setEnabled(false);
        ui->accBox_2->setEnabled(false);
        ui->accBox_3->setEnabled(false);
        ui->accuracyButton->setEnabled(false);
        ui->accLabel->setEnabled(false);
        ui->accLabel_2->setEnabled(false);
        ui->accLabel_3->setEnabled(false);
        ui->accWeightLabel->setEnabled(false);
        ui->MHaccLabel->setEnabled(false);
        ui->MHmaxBox->setEnabled(false);
        ui->MHmaxLabel->setEnabled(false);
        ui->MHminBox->setEnabled(false);
        ui->MHminLabel->setEnabled(false);
        ui->enemyArmorBox->setEnabled(false);
        ui->enemyArmorLabel->setEnabled(false);
        ui->enemyLevelBox->setEnabled(true);
        ui->enemyLevelLabel->setEnabled(true);
        ui->armorBox->setEnabled(true);
        ui->armorLabel->setEnabled(true);
        ui->defBox->setEnabled(true);
        ui->defLabel->setEnabled(true);
        ui->shieldBox->setEnabled(true);
        ui->shieldLabel->setEnabled(true);
        ui->absorbBox->setEnabled(true);
        ui->absorbLabel->setEnabled(true);
        ui->calcDPSButton->setText("Calculate Mitigation");
        ui->DPSlabel_1->setText("Mitigation");

        //        ui->forceTechButton->setEnabled(false);
        //        ui->shadowTechButton->setEnabled(false);
        //        ui->combatTechButton->setEnabled(true);
        //        ui->combatTechButton->setChecked(true);

        ui->powerButton->setText("Armor");
        ui->aimButton->setText("Defense");
        ui->critButton->setText("Shield");
        ui->surgeButton->setText("Absorb");
        ui->accuracyButton->setVisible(false);
        ui->alacrityButton->setVisible(false);

        ui->skill_label_8->setVisible(false);
        ui->skillBox_8->setVisible(false);
        ui->skill_label_9->setVisible(false);
        ui->skillBox_9->setVisible(false);
        ui->skill_label_10->setVisible(false);
        ui->skillBox_10->setVisible(false);

        ui->optionBox_1->setVisible(false);
        ui->optionLabel->setVisible(false);
        ui->optionLabel_1_2->setVisible(false);
        ui->optionBox_2->setVisible(false);
        ui->optionLabel_2->setVisible(false);
        ui->optionBox_3->setVisible(false);
        ui->optionLabel_3->setVisible(false);
        ui->optionBox_4->setVisible(false);
        ui->optionLabel_4->setVisible(false);
        ui->optionLabel_4_2->setVisible(false);

        ui->upg1Label->setText("Item 1 Mitigation: ");
        ui->upg2Label->setText("Item 2 Mitigation: ");
        getMitigation(0,0,0,0);
    }

    if(ui->tree2->isChecked()){
        //        ui->forceTechButton->setEnabled(true);
        //        ui->shadowTechButton->setEnabled(true);
        //        ui->combatTechButton->setEnabled(false);
        //        ui->shadowTechButton->setChecked(true);
    }
    if(ui->tree3->isChecked()){
        //        ui->forceTechButton->setEnabled(true);
        //        ui->shadowTechButton->setEnabled(true);
        //        ui->combatTechButton->setEnabled(false);
        //        ui->forceTechButton->setChecked(true);
    }
}

double Guardian::calculateDPS(){
    double DPS = 0;
    setStats();
    if(ui->tree1->isChecked()){
        double mit = getMitigation(0,0,0,0);

        ui->countView->insertPlainText(QString::number(mit));
    }
    double rotationTime = ui->numCasts->value();
    int numCasts = ui->numCasts->value();
    if(ui->fixedTimeButton->isChecked()){
        //    DPS = bodyguardRotation(rotationTime, shStats);
    }else{
        //    DPS = bodyguardRotation(numCasts, shStats);
    }

    return DPS;
}

void Guardian::getWeights(){
    //copy stats for modification
    setStats();
    vector <double> stats2 = guardStats;
    double baseDPS, aimDPS, cunningDPS, powerDPS, critDPS, surgeDPS, alacDPS =0, refStat=1;

    double statBuff = 1+0.03*(ui->skillBox_1->value());
    std::vector <double> weights(8,0);
    for(int m=0;m<7;m++){
        stats2 = guardStats;
        switch(m){
        case 0:
            break;
        case 1:
            stats2.at(STRENGTH)+= (1*statBuff);
            break;
        case 2:
            stats2.at(POWER)+=1;
            break;
        case 3:
            stats2.at(CRIT)+=1;
            break;
        case 4:
            stats2.at(SURGE)+=1;
            break;
        case 5:
            stats2.at(ALACRITY)+=1;
            break;
        case 6:
            stats2.at(WILLPOWER)+=1;
            break;
        default:
            break;
        }
        stats2 = calculateStats(stats2);
        if(ui->fixedTimeButton->isChecked()){
            double numCasts = ui->numCasts->value();
            //    weights.at(m)=bodyguardRotation(numCasts, stats2);
        }else{
            int numCasts = ui->numCasts->value();
            //   weights.at(m)=bodyguardRotation(numCasts, stats2);
        }

    }
    baseDPS = weights.at(0);
    aimDPS = weights.at(1) -baseDPS;
    powerDPS = weights.at(2) -baseDPS;
    critDPS = weights.at(3) -baseDPS;
    surgeDPS = weights.at(4) -baseDPS;
    alacDPS = weights.at(5) -baseDPS;
    cunningDPS = weights.at(6) -baseDPS;

    if(ui->powerButton->isChecked())refStat = powerDPS;
    if(ui->aimButton->isChecked())refStat = aimDPS;
    if(ui->critButton->isChecked())refStat = critDPS;
    if(ui->surgeButton->isChecked())refStat = surgeDPS;
    if(ui->alacrityButton->isChecked())refStat = alacDPS;
    //if(ui->accuracyButton->isChecked())refStat = accuracyDPS;

    double powerWeight = powerDPS/refStat;
    double aimWeight = aimDPS/refStat;
    double cunningWeight = cunningDPS/refStat;
    double critWeight = critDPS/refStat;
    double surgeWeight = surgeDPS/refStat;
    double alacWeight = alacDPS/refStat;

    ui->critWeightLabel->setText(QString::number(critWeight));
    ui->surgeWeightLabel->setText(QString::number(surgeWeight));
    ui->alacWeightLabel->setText(QString::number(alacWeight));
    ui->powerWeightLabel->setText(QString::number(powerWeight));
    ui->primaryWeightLabel->setText(QString::number(aimWeight));
    ui->secondaryWeightLabel->setText(QString::number(cunningWeight));

    if(ui->tree1->isChecked()){
        double armor = getMitigation(100, 0, 0, 0) - getMitigation(0, 0, 0, 0);
        double def = getMitigation(0, 1, 0, 0) - getMitigation(0, 0, 0, 0);
        double shield = getMitigation(0, 0, 1, 0) - getMitigation(0, 0, 0, 0);
        double absorb = getMitigation(0, 0, 0, 1) - getMitigation(0, 0, 0, 0);

        double refStat;
        if(ui->powerButton->isChecked())refStat = armor;
        if(ui->aimButton->isChecked())refStat = def;
        if(ui->critButton->isChecked())refStat = shield;
        if(ui->surgeButton->isChecked())refStat = absorb;

        double armorWeight = armor/refStat;
        double defenseWeight = def/refStat;
        double shieldWeight = shield/refStat;
        double absorbWeight = absorb/refStat;
        ui->armorWeightLabel->setText(QString::number(armorWeight));
        ui->defenseWeightLabel->setText(QString::number(defenseWeight));
        ui->shieldWeightLabel->setText(QString::number(shieldWeight));
        ui->absorbWeightLabel->setText(QString::number(absorbWeight));

    }
}

void Guardian::compareUpgrades(){
    setStats();
    vector <double> stats1 = guardStats;
    vector <double> stats2 = guardStats;
    double baseDPS = 0, upg1DPS = 1, upg2DPS = 2;
    if((ui->tree2->isChecked())||(ui->tree3->isChecked())){
        double rotationTime = ui->numCasts->value();
        int numCasts = ui->numCasts->value();

        double statBuff = 1 + 0.03*(ui->skillBox_1->value());
        if(ui->consularCheckBox->isChecked()) statBuff += 0.05;

        if(ui->fixedTimeButton->isChecked()){
            //    baseDPS = bodyguardRotation(rotationTime, shStats);
        }else{
            //    baseDPS = bodyguardRotation(numCasts, shStats);
        }
        //populate upgrade 1
        stats1.at(STRENGTH) += (ui->primaryBox_2->value())*statBuff;
        stats1.at(WILLPOWER) += ui->secondaryBox_2->value();
        stats1.at(CRIT) += ui->critBox_2->value();
        stats1.at(SURGE) += ui->surgeBox_2->value();
        stats1.at(POWER) += ui->powerBox_2->value() + ui->techBox_2->value();
        stats1.at(ALACRITY) += ui->alacBox_2->value();

        stats1 = calculateStats(stats1);

        if(ui->fixedTimeButton->isChecked()){
            //    upg1DPS = bodyguardRotation(rotationTime, stats1);
        }else{
            //    upg1DPS = bodyguardRotation(numCasts, stats1);
        }

        //populate upgrade 2
        stats2.at(STRENGTH) += (ui->primaryBox_3->value())*statBuff;
        stats2.at(WILLPOWER) += ui->secondaryBox_3->value();
        stats2.at(CRIT) += ui->critBox_3->value();
        stats2.at(SURGE) += ui->surgeBox_3->value();
        stats2.at(POWER) += ui->powerBox_3->value() + ui->techBox_2->value();
        stats2.at(ALACRITY) += ui->alacBox_3->value();

        stats2 = calculateStats(stats2);
        if(ui->fixedTimeButton->isChecked()){
            //    upg2DPS = bodyguardRotation(rotationTime, stats2);
        }else{
            //    upg2DPS = bodyguardRotation(numCasts, stats2);
        }

        upg1DPS -= baseDPS;
        upg2DPS -= baseDPS;
        ui->DPSlabel_2->setText(QString::number(upg1DPS));
        ui->DPSlabel_3->setText(QString::number(upg2DPS));

        if(upg1DPS == upg2DPS) ui->upg3Label->setText("No difference");
        if(upg1DPS > upg2DPS) ui->upg3Label->setText("Use Item 1");
        if(upg1DPS < upg2DPS) ui->upg3Label->setText("Use Item 2");
    }
    if(ui->tree1->isChecked()){
        double d_armor = ui->armorBox_2->value();
        double d_def = ui->defBox_2->value();
        double d_absorb = ui->absorbBox_2->value();
        double d_shield = ui->shieldBox_2->value();
        double mitigation1 = getMitigation(d_armor, d_def, d_shield, d_absorb) - getMitigation(0, 0, 0, 0);
        ui->DPSlabel_2->setText(QString::number(mitigation1));
        d_armor = ui->armorBox_3->value();
        d_def = ui->defBox_3->value();
        d_absorb = ui->absorbBox_3->value();
        d_shield = ui->shieldBox_3->value();
        double mitigation2 = getMitigation(d_armor, d_def, d_shield, d_absorb) - getMitigation(0, 0, 0, 0);
        ui->DPSlabel_3->setText(QString::number(mitigation2));
        if(mitigation1 == mitigation2) ui->upg3Label->setText("No difference");
        if(mitigation1 > mitigation2) ui->upg3Label->setText("Use Item 1");
        if(mitigation1 < mitigation2) ui->upg3Label->setText("Use Item 2");
    }
}

void Guardian::on_calcDPSButton_clicked()
{
    updateStatBoxes();
    //    double HPS = calculateHPS();
    //    ui->castView->clear();
    //    ui->countView->clear();
    //    QString countString = "RSc casts: " + QString::number(RSc_count)+"\nHSc casts: " + QString::number(HSc_count)
    //            +"\nRSh casts: " + QString::number(RSh_count)+ "\nRSc casts in SCG: " + QString::number(RSc_SCG_count)
    //            +"\nHSc casts in SCC: " + QString::number(HSc_SCG_count) +"\nRSh casts in SCG: " + QString::number(RSh_SCG_count)
    //            +"\nES casts: " + QString::number(ES_count) +"\nSCG usages: " + QString::number(SCG_count)
    //            +"\nVH usages: " + QString::number(VH_count);
    //    ui->countView->insertPlainText(countString);
    //    ui->castView->insertPlainText(guardRotationOutput);
    //    ui->HPSlabel->setText(QString::number(HPS));
}

void Guardian::on_primaryBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_powerBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_critBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_alacBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_levelBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_secondaryBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_techBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_surgeBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_accBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_MHmaxBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_MHminBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_enemyLevelBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_enemyArmorBox_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_calcWeightButton_clicked()
{
    updateStatBoxes();
    getWeights();
}

void Guardian::on_upgradeButton_clicked()
{
    compareUpgrades();
}

void Guardian::on_computeAlacrityButton_clicked()
{
    computeAlacrity();
}

void Guardian::on_skillBox_1_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_skillBox_2_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_skillBox_3_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_skillBox_4_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_skillBox_5_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_skillBox_6_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_skillBox_7_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_skillBox_8_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_skillBox_9_editingFinished()
{
    updateStatBoxes();
}

void Guardian::on_note1_clicked()
{
    ui->countView->clear();
    QString note1 = "*Note that Crit Size may differ from the value in game because Warden only affects heals, so does not show up on the in-game tooltip.";
    ui->countView->insertPlainText(note1);
}

void Guardian::on_note2_clicked()
{
    ui->countView->clear();
    QString note2 = "**Note 2: Alacrity has complex interactions with SCG windows, resource mechanics, Effective Cost of abilities, etc.\n\n Current recommendation is for 5-7.5% Alacrity, not to exceed 8.5% for Commandos or 12.5% for Mercs. The difference is due to imbalance in their resource regen windows.  While Alacrity is not good for Mercs, it is especially bad for Commandos.\n\n For more information, see the following two threads on the SWTOR.com forums\n\n http://www.swtor.com/community/showthread.php?p=2900243#post2900243\n\nhttp://www.swtor.com/community/showthread.php?t=306667";
    ui->countView->insertPlainText(note2);
}

void Guardian::on_saveStats_clicked()
{
    setStats();
    string filename = "Guardian_stats.txt";
    ofstream fout (filename.c_str());
    fout << guardStats.at(STRENGTH) << "\n" << guardStats.at(WILLPOWER) << "\n" << guardStats.at(CRIT)<< "\n" <<
            guardStats.at(SURGE) << "\n" << ui->powerBox->value() << "\n" << ui->techBox->value() << "\n" << guardStats.at(ALACRITY) << "\n" <<
            guardStats.at(LEVEL) << "\n" << guardStats.at(ACCURACY) << "\n" << guardStats.at(MH_MAX) << "\n" <<
            guardStats.at(MH_MIN) << "\n" << guardStats.at(ENEMY_LEVEL) << "\n" << guardStats.at(ENEMY_ARMOR) << endl;

    fout << ui->skillBox_1->value() << "\n" << ui->skillBox_2->value() << "\n" << ui->skillBox_3->value() << "\n" <<
            ui->skillBox_4->value() << "\n" << ui->skillBox_5->value() << "\n" << ui->skillBox_6->value() << "\n" <<
            ui->skillBox_7->value() << "\n" << ui->skillBox_8->value() << "\n" << ui->skillBox_9->value() << "\n" << endl;

    fout << guardStats.at(OH_MAX) << "\n" << guardStats.at(OH_MIN) << endl;
    fout.close();
}

void Guardian::on_loadStats_clicked()
{
    Load_Stats();
}

void Guardian::Load_Stats(){
    string filename = "Guardian_stats.txt";
    ifstream fin (filename.c_str());
    vector <string> inputStats(27,"0");
    int i=0;
    while(fin.good()){
        getline(fin,inputStats.at(i));
        i++;
    }
    ui->primaryBox->setValue(atoi(inputStats.at(0).c_str()));
    ui->secondaryBox->setValue(atoi(inputStats.at(1).c_str()));
    ui->critBox->setValue(atoi(inputStats.at(2).c_str()));
    ui->surgeBox->setValue(atoi(inputStats.at(3).c_str()));
    ui->powerBox->setValue(atoi(inputStats.at(4).c_str()));
    ui->techBox->setValue(atoi(inputStats.at(5).c_str()));
    ui->alacBox->setValue(atoi(inputStats.at(6).c_str()));
    ui->levelBox->setValue(atoi(inputStats.at(7).c_str()));
    ui->accBox->setValue(atoi(inputStats.at(8).c_str()));
    ui->MHmaxBox->setValue(atoi(inputStats.at(9).c_str()));
    ui->MHminBox->setValue(atoi(inputStats.at(10).c_str()));
    ui->enemyLevelBox->setValue(atoi(inputStats.at(11).c_str()));
    ui->enemyArmorBox->setValue(atoi(inputStats.at(12).c_str()));

    //set skill boxes
    ui->skillBox_1->setValue(atoi(inputStats.at(13).c_str()));
    ui->skillBox_2->setValue(atoi(inputStats.at(14).c_str()));
    ui->skillBox_3->setValue(atoi(inputStats.at(15).c_str()));
    ui->skillBox_4->setValue(atoi(inputStats.at(16).c_str()));
    ui->skillBox_5->setValue(atoi(inputStats.at(17).c_str()));
    ui->skillBox_6->setValue(atoi(inputStats.at(18).c_str()));
    ui->skillBox_7->setValue(atoi(inputStats.at(19).c_str()));
    ui->skillBox_8->setValue(atoi(inputStats.at(20).c_str()));
    ui->skillBox_9->setValue(atoi(inputStats.at(21).c_str()));


    fin.close();
}


void Guardian::on_check2pcBox_toggled(bool checked)
{
    if(checked==false) ui->check4pcBox->setChecked(false);
}

void Guardian::on_check4pcBox_toggled(bool checked)
{
    if(checked==true) ui->check2pcBox->setChecked(true);
}

void Guardian::on_tree1_clicked()
{
    updateStatBoxes();
}

void Guardian::on_tree2_clicked()
{
    updateStatBoxes();
}

void Guardian::on_tree3_clicked()
{
    updateStatBoxes();
}
